﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.IO;
namespace CricketHub
{
    public class LiveScore_req
    {
        HttpWebRequest request;
        public Livescore htt;
        public void htm()
        {
            try
            {
                request = (HttpWebRequest)WebRequest.Create("http://www.espncricinfo.com/ci/engine/current/match/scores/liveframe.html?mode=realtime");
                request.Headers["referer"] = string.IsNullOrEmpty(string.Empty).ToString();

                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(Resp), this);
            }
            catch (Exception not)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the network connection");
                });
 
            }
        }
        StringBuilder browserdata = new StringBuilder();
        private void Resp(IAsyncResult asyn)
        {
            try
            {
                LiveScore_req ht = (LiveScore_req)asyn.AsyncState;
                HttpWebRequest req2 = request;
                HttpWebResponse resp = (HttpWebResponse)req2.EndGetResponse(asyn);
                Stream stream = resp.GetResponseStream();
                StreamReader read = new StreamReader(stream);
                string webdata = read.ReadToEnd();
                string actual = webdata.Replace("Live scorecard", "");
                string actual1 = actual.Replace("Desktop scorecard", "");//Desktop scorecard
                string actual2 = actual1.Replace("Commentary", "");
                string actual3 = actual2.Replace("Photo index", "");
                string actual4 = actual3.Replace("Report", "");
                string actual5 = actual4.Replace("|", "");
                string actual6 = actual5.Replace("(1)", "");
                string actual7 = actual6.Replace("(2)", "");
                string actual8 = actual7.Replace("(3)", "");
                string actual9 = actual8.Replace("(4)", "");
                string actual10 = actual9.Replace("(5)","");
                string actual11 = actual10.Replace("(6)","");
                string actual12 = actual11.Replace("(7)", "");
                string actual13 = actual12.Replace("(8)", "");
                string actual14 = actual13.Replace("(9)", "");
                string actual15 = actual14.Replace("Article index", "");
                string hackstring = "<meta name=\"viewport\" content=\"width=320,user-scalable=yes,initial-scale=10.0\"/>";
                string cc = actual15.Insert(actual15.IndexOf("<head>", 0) + 6, hackstring);
               // htt.Browser_data(actual4);
                htt.Browser_data(cc);



                htt.Browser_data(actual4);
            }
            catch (Exception notex)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Please check the network connection");
                    });
            }
        }

    }
}
